/*
 * Created on 2008-06-08
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package elka.isi.operator.writer;

import org.evolvica.core.IIndividualSet;

import elka.isi.util.RWUtils;

public class PopulationsQuantityWriter extends EcosystemStateWriter {

	public PopulationsQuantityWriter(String filename) {
		super(filename);
	}

	public int prevSecondRabbitsCount = 0;
	public int prevSecondWolvesCount = 0;
	public int prevSecondRoesCount = 0;

	public int prevFirstRabbitsCount = 0;
	public int prevFirstWolvesCount = 0;
	public int prevFirstRoesCount = 0;

	/**
	 * Zapisuje do pliku liczebnosci wszystkich populacji w danym momencie
	 * cyklu, w kazdej iteracji.
	 */
	public void write(IIndividualSet set) {
		int rabbitsCount = RWUtils.getRabbits(set).size();
		int wolvesCount = RWUtils.getWolves(set).size();
		int roesCount = RWUtils.getRoes(set).size();
		int rabbitsCountToPrint =
			(rabbitsCount + prevFirstRabbitsCount + prevSecondRabbitsCount) / 3;
		int wolvesCountToPrint =
			(wolvesCount + prevFirstWolvesCount + prevSecondWolvesCount) / 3;
		int roesCountToPrint = (roesCount + prevFirstRoesCount + prevSecondRoesCount) / 3;
		writer.append(
		rabbitsCountToPrint
				+ DELIMITER
				+ wolvesCountToPrint
				+ DELIMITER
				+ roesCountToPrint
				+ "\n");

		prevSecondRabbitsCount = prevFirstRabbitsCount;
		prevSecondWolvesCount = prevFirstWolvesCount;
		prevSecondRoesCount = prevFirstRoesCount;

		prevFirstRabbitsCount = rabbitsCount;
		prevFirstWolvesCount = wolvesCount;
		prevFirstRoesCount = roesCount;

	}
}